class Solution(object):
    def findPeakElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        left_index = 0
        right_index = len(nums) - 1
        while right_index - left_index >= 2:
            mid_index = (left_index + right_index) // 2
            if nums[mid_index] < nums[mid_index + 1]:
                left_index = mid_index
            else:
                if nums[mid_index] > nums[mid_index - 1]:
                    return mid_index
                else:
                    right_index = mid_index
        if right_index == left_index:
            return left_index
        else:
            if nums[left_index] > nums[right_index]:
                return left_index
            else:
                return right_index


data = Solution()
nums = [1, 2, 1, 3, 5, 6, 4]
print(data.findPeakElement(nums))
nums = [3]
print(data.findPeakElement(nums))